Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports DotNetNuke
Imports ModuleMasters.DNN.Modules.NCAAPoolStandings.Business

Namespace ModuleMasters.DNN.Modules.NCAAPoolStandings

    Public MustInherit Class Settings
		Inherits Entities.Modules.ModuleSettingsBase

#Region "Controls"
#End Region


        Public Overrides Sub LoadSettings()
            Try
                If Not Page.IsPostBack Then
                    ' Load settings from TabModuleSettings: specific to this instance
                    Dim objNCAAPoolStandings As New NCAAPoolStandingsController
                    Dim listModules As ArrayList

                    Dim PoolBracketModuleId As String = CType(ModuleSettings("PoolBracketModuleId"), String)

                    listModules = objNCAAPoolStandings.GetModuleList(PortalId)
                    viewstate.Add("ModuleList", listModules)

                    Me.cmbPoolBracketModuleId.DataSource = listModules
                    Me.cmbPoolBracketModuleId.DataValueField = "ModuleId"
                    Me.cmbPoolBracketModuleId.DataTextField = "TabModule"
                    
                    Me.cmbPoolBracketModuleId.DataBind()

                    Try
                        Me.cmbPoolBracketModuleId.SelectedValue = PoolBracketModuleId
                    Catch exc As Exception
                        Me.cmbPoolBracketModuleId.SelectedIndex = 0
                    End Try

                    If Not Settings("UserNameDisplayOption") Is Nothing Then

                        Dim txtUserNameDisplayOption As String = CType(ModuleSettings("UserNameDisplayOption"), String)

                        If txtUserNameDisplayOption = "UserLoginName" Then
                            Me.rbUserLoginName.Checked = True
                        Else
                            Me.rbUserFirstLastName.Checked = True
                        End If
                    Else
                        Me.rbUserLoginName.Checked = True
                    End If

                End If
            Catch exc As Exception
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

        Public Overrides Sub UpdateSettings()
            Try
                Dim objModules As New Entities.Modules.ModuleController

                ' Update TabModuleSettings
                objModules.UpdateModuleSetting(ModuleId, "PoolBracketModuleId", Me.cmbPoolBracketModuleId.SelectedValue)

                'also update setting to show the poolbrackettabid
                Dim tabid As Integer
                Dim listModules As ArrayList
                listModules = CType(viewstate.Item("ModuleList"), ArrayList)
                Dim ModuleInfo As ModuleListInfo
                For Each ModuleInfo In listModules
                    If CInt(Me.cmbPoolBracketModuleId.SelectedValue) = ModuleInfo.ModuleId Then
                        tabid = ModuleInfo.TabId
                    End If
                Next
                objModules.UpdateModuleSetting(ModuleId, "PoolBracketTabId", tabid.ToString)

                If Me.rbUserLoginName.Checked = True Then
                    objModules.UpdateModuleSetting(ModuleId, "UserNameDisplayOption", "UserLoginName")
                Else
                    objModules.UpdateModuleSetting(ModuleId, "UserNameDisplayOption", "UserFirstLastName")
                End If

                ' Redirect back to the portal home page
                Response.Redirect(NavigateURL(), True)
            Catch exc As Exception
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

#Region " Web Form Designer Generated Code "

        'This call is required by the Web Form Designer.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

        End Sub
        Protected WithEvents plPoolBracketModuleId As DotNetNuke.UI.UserControls.LabelControl
        Protected WithEvents cmbPoolBracketModuleId As System.Web.UI.WebControls.DropDownList
        Protected WithEvents rbUserName As System.Web.UI.WebControls.RadioButton
        Protected WithEvents rbUserFirstLastName As System.Web.UI.WebControls.RadioButton
        Protected WithEvents rbUserLoginName As System.Web.UI.WebControls.RadioButton

        'NOTE: The following placeholder declaration is required by the Web Form Designer.
        'Do not delete or move it.
        Private designerPlaceholderDeclaration As System.Object

        Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
            'CODEGEN: This method call is required by the Web Form Designer
            'Do not modify it using the code editor.
            InitializeComponent()
        End Sub

#End Region

    End Class

End Namespace
